var rule;
var share;
$(function(){
	$.ajax({
		url:'../nameController/getRules',
		success:function(data){
			console.log(data);
			rule=data;
		}
	})
})

$("#close").click(function(){
	$(".poster").css("display","none");
})

$(function(){
	$.ajax({
		url:'../bannerController/getShare',
		success:function(data){
			console.log(data);
			share=data;
			if(data.day==0 && data.num==1){
				$(".share1").unbind("click");
				$(".share2").unbind("click");
				$(".share1").css("background","url(../image/hui.png) no-repeat")
				$(".share1").css("background-size","100% 100%")
				$(".share1 img").attr("src","../image/huiShare.png")
			}
			if(data.day==0 && data.num==2){
				$(".share1").unbind("click");
				$(".share2").unbind("click");
				$(".share1").css("background","url(../image/hui.png) no-repeat")
				$(".share1").css("background-size","100% 100%")
				$(".share1 img").attr("src","../image/huiShare.png")
				$(".share2").css("background","url(../image/hui.png) no-repeat")
				$(".share2").css("background-size","100% 100%")
				$(".share2 img").attr("src","../image/huiShare.png")
			}
			if(data.day==1 && data.num==1){
				$(".share1").unbind("click");
				$(".share2").css("background","url(../image/shareBack.png) no-repeat")
				$(".share2").css("background-size","100% 100%")
				$(".share2 img").attr("src","../image/share.png")
			}
			if(data.day==1 && data.num==2){
				$(".share2").unbind("click");
				$(".share2").css("background","url(../image/hui.png) no-repeat")
				$(".share2").css("background-size","100% 100%")
				$(".share2 img").attr("src","../image/huiShare.png")
				$(".share1").css("background","url(../image/shareBack.png) no-repeat")
				$(".share1").css("background-size","100% 100%")
				$(".share1 img").attr("src","../image/share.png")
			}
			if(data.day>1 || data==null || data==""){
				$(".share2").unbind("click");
				$(".share2").css("background","url(../image/hui.png) no-repeat")
				$(".share2").css("background-size","100% 100%")
				$(".share2 img").attr("src","../image/huiShare.png")
				$(".share1").css("background","url(../image/shareBack.png) no-repeat")
				$(".share1").css("background-size","100% 100%")
				$(".share1 img").attr("src","../image/share.png")
			}
		}
	})
})

$(".share1").click(function(){
	$.ajax({
		url:'../bannerController/saveShare',
		data:{
			"num":1
		},
		success:function(data){
			console.log(data);
			if(data){
				
				$(".share1").unbind("click");
				$(".share1").css("background","url(../image/hui.png) no-repeat")
				$(".share1").css("background-size","100% 100%")
				$(".share1 img").attr("src","../image/huiShare.png")
				$(".posterBox").html("<img src='"+rule.remark1+"'>")
				$(".poster").css("display","flex");
			}
		}
	})
})
$(".share2").click(function(){
	
	$.ajax({
		url:'../bannerController/saveShare',
		data:{
			"num":2
		},
		success:function(data){
			console.log(data);
			if(data){
				
				$(".share1").unbind("click");
				$(".share2").css("background","url(../image/hui.png) no-repeat")
				$(".share2").css("background-size","100% 100%")
				$(".share2 img").attr("src","../image/huiShare.png")
				$(".posterBox").html("<img src='"+rule.remark1+"'>")
				$(".poster").css("display","flex");
			}
		}
	})
})
$(".share3").click(function(){
	console.log(rule)
	$(".poster").css("display","flex");
	$(".posterBox").html("<img src='"+rule.card+"'>")
})
$(".withdrawal").click(function(){
	window.location.href="../html/myTicket.html"
})